package com.dc.adaptor.passive;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;


public class PassiveRecevier {
	
	protected ThreadLocal<BlockingQueue<String>> threadLocal = new ThreadLocal<BlockingQueue<String>>();
	
	protected void putMessage(String queueId,String content){
		
		Message message = new Message();
		BlockingQueue<String> queue = new ArrayBlockingQueue<String>(1);
		message.setQueue(queue);
		message.setMessage(content);
		QueueFactory.getQueue(queueId).add(message);
		threadLocal.set(queue);
	}
	
	protected String getResponce(long timeout, TimeUnit unit) throws Exception{
		BlockingQueue<String> queue = threadLocal.get();
		threadLocal.remove();
		return queue.poll(timeout, unit);
	}
	
}
